<?php
$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password="root"; // Mysql password 
$db_name="db431888431"; // Database name 

$dbLink = mysql_connect($host, $username, $password);

?>

<html>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> 
<style TYPE="text/css">

table { 
	margin: 1em; 
	border-collapse: collapse;
	text-align: center;
	font-family: Verdana;
	font-weight: normal;
	font-size: 11px;
	}
td, th { padding: .3em; border: 1px #ccc solid; }
thead { background: #c8faab; }
tbody { background: #ffffff; }
#highlight tr.hilight { background: #dfffe1; }


td.birdie {
	background-color: #6ecdff;
}
td.eagle {
	background-color: #c4fbff;
}
td.albatross {
	background-color: #ff00f2;
}
td.bogey {
	background-color: #fcf74f;
}
td.doublebogey {
	background-color: #ffb700;
}
td.triplebogey {
	background-color: #ff0000;
}


.button {
    border: 1px solid #006;
    background: #dfffe1;
}


body {
	font-family: Helvetica, Arial, sans-serif;
	font-size: small;		
}

#header {
  background: black url(images/header.jpg) center no-repeat;
  height: 200;
}

</style>

<script type="text/javascript">
	function rechercherParcours(str)
	{
		if (str=="") {
			document.getElementById("txtHint").innerHTML="";
			return;
			} 
		if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		}
		else {	
		// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4 && xmlhttp.status==200) {
				document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
			}
		}
		xmlhttp.open("GET","_rechercheParcours.php?idparcours="+str,true);
		xmlhttp.send();
	}
</script>

<body>


Sélectionnez le parcours de golf: 
	<select name="listeParcours" onchange="rechercherParcours(this.value)">
	<option value="">Liste des parcours disponibles</option>
	<?php
	echo "on execute la connexion";
	if (!$dbLink) die("Impossible d'établir une connexion sur la base de données: " . mysql_error());
	$dbSelected = mysql_select_db($db_name, $dbLink);
	if (!$dbSelected) die ('We\'re connected, but can\'t use the table: ' . mysql_error());

	$queryCourse = 'SELECT id, name FROM courses order by id';
	$resultCourse 	= mysql_query($queryCourse);
	
	var_dump($resultCourse);
	if(mysql_num_rows($resultCourse) ){
		while($rowCourse = mysql_fetch_array($resultCourse))  {
			echo "<option value=\"".$rowCourse['id'] . "\">". $rowCourse['name'] . "</option>";
			
		}	
	}
	else {
		echo "aucun parcours trouvé.";
	}
	?>
</select>

<div id="txtHint"></div>
</body>
</html>